import { Body, Controller, Get, Param, ParseIntPipe, Post, Query, UseGuards } from '@nestjs/common';
import {
  CreateCategoryDto,
  DeleteCategoryDto,
  QueryCategoryDto,
  UpdateCategoryDto,
} from './dto/dto';
import { ArticleCategoryService } from '@/modules/article/article_category/category.service';
import { QueryListDto } from '@/modules/article/dto/dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('article/category')
export class ArticleCategoryController {
  constructor(private readonly articleCategoryService: ArticleCategoryService) {}

  // 获取分类总数
  @Get('/total')
  async categoryTotal() {
    return await this.articleCategoryService.categoryTotal();
  }

  // 获取分类的文章总数
  @Get(':id/article/total')
  async categoryArticleTotal(@Param('id', ParseIntPipe) id: number) {
    return await this.articleCategoryService.categoryArticleTotal(id);
  }
  // 按条件对象查询分类列表
  @UseGuards(AuthGuard('jwt'))
  @Get('/query')
  async articleQuery(@Query() data: QueryListDto) {
    return await this.articleCategoryService.articleCategoryQuery(data);
  }

  // 获取分类列表
  @Get('/list')
  async categoryList(@Query() data: QueryCategoryDto) {
    return await this.articleCategoryService.categoryList(data);
  }

  // 按id获取分类信息
  @Get(':id')
  async categoryFindOne(@Param('id', ParseIntPipe) id: number) {
    return await this.articleCategoryService.categoryFindOne(id);
  }

  // 按分类id获取文章列表
  @Get(':id/article')
  async categoryArticle(@Query() data: QueryCategoryDto, @Param('id', ParseIntPipe) id: number) {
    return await this.articleCategoryService.categoryArticle(data, id);
  }

  // 创建分类
  @UseGuards(AuthGuard('jwt'))
  @Post('/create')
  async createCategory(@Body() data: CreateCategoryDto) {
    return await this.articleCategoryService.createCategory(data);
  }

  // 更新分类
  @UseGuards(AuthGuard('jwt'))
  @Post('/update/:id')
  async updateCategory(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateCategoryDto) {
    return await this.articleCategoryService.updateCategory(id, data);
  }

  // 批量删除分类
  @UseGuards(AuthGuard('jwt'))
  @Post('/remove')
  async removeCategory(@Body() data: DeleteCategoryDto) {
    return await this.articleCategoryService.removeCategory(data);
  }

  // 按id删除分类
  @UseGuards(AuthGuard('jwt'))
  @Post('/remove/:id')
  async removeCategoryOne(@Param('id', ParseIntPipe) id: number) {
    return await this.articleCategoryService.removeCategoryOne(id);
  }
}
